/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fh.view.tourney;

import fh.view.running.CurrentTourneyOverview;
import fh.component.DateParser;
import fh.controller.EventController;
import fh.controller.LocationController;
import fh.controller.PlayerController;
import fh.model.Event;
import fh.model.Location;
import fh.model.Player;
import fh.view.*;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 *
 * @author Bart
 */
public class DetailTourney extends javax.swing.JFrame {

    LocationController lc;
    Event anEvent;
    EventController ec;
    PlayerController pc;

    /**
     * Creates new form DetailTourney
     */
    public DetailTourney() {
        initComponents();
    }

    public DetailTourney(Event event) {
        initComponents();
        lc = new LocationController();
        anEvent = event;
        ec = new EventController();
        pc = new PlayerController();
        FillList();
        FillForm();

    }

    private void FillList() {
        DefaultComboBoxModel players = pc.getEventPlayerList(anEvent.getId());
        PlayerList.clearSelection();
        PlayerList.setModel(players);
    }

    private void FillForm() {
        NameTourneyField.setText(anEvent.getName());
        DateTourneyField.setText(DateParser.mySqlDateToString(anEvent.getDate()));
        MaxPlayersTourneyField.setText(anEvent.getMax_players() + "");
        EntryFeeTourneyField.setText(anEvent.getEntry_fee() + "");
        TableCapTourneyField.setText(anEvent.getTable_cap() + "");
        Location currentLocation = lc.getLocationById(anEvent.getLocation_id());
        lblCurrentLocation.setText(currentLocation.toString());

    }

    private Player getPlayer() {

        Player player = (Player) PlayerList.getSelectedValue();
        return player;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        CurrentTourneyButton = new javax.swing.JButton();
        LocationEventMainButton = new javax.swing.JButton();
        PlayerOverviewButton = new javax.swing.JButton();
        EditTourneyButton = new javax.swing.JButton();
        TableCapTourneyField = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        EntryFeeTourneyField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        MaxPlayersTourneyField = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        DateTourneyField = new javax.swing.JTextField();
        NameTourneyField = new javax.swing.JTextField();
        BacktoOverviewButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        PlayerList = new javax.swing.JList();
        jLabel8 = new javax.swing.JLabel();
        EditPaymentStatusButton = new javax.swing.JButton();
        lblCurrentLocation = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Detail toernooi");
        setForeground(java.awt.Color.white);
        setMaximumSize(new java.awt.Dimension(800, 600));
        setMinimumSize(new java.awt.Dimension(800, 600));
        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 30)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Full House");
        jLabel1.setToolTipText("");

        CurrentTourneyButton.setText("Toernooi runnen");
        CurrentTourneyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CurrentTourneyButtonActionPerformed(evt);
            }
        });

        LocationEventMainButton.setText("Locatie & Event");
        LocationEventMainButton.setMaximumSize(new java.awt.Dimension(111, 23));
        LocationEventMainButton.setMinimumSize(new java.awt.Dimension(111, 23));
        LocationEventMainButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                LocationEventMainButtonActionPerformed(evt);
            }
        });

        PlayerOverviewButton.setText("Speler beheer");
        PlayerOverviewButton.setMaximumSize(new java.awt.Dimension(111, 23));
        PlayerOverviewButton.setMinimumSize(new java.awt.Dimension(111, 23));
        PlayerOverviewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PlayerOverviewButtonActionPerformed(evt);
            }
        });

        EditTourneyButton.setText("Wijzigen");
        EditTourneyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditTourneyButtonActionPerformed(evt);
            }
        });

        TableCapTourneyField.setEditable(false);

        jLabel3.setText("Datum:");

        EntryFeeTourneyField.setEditable(false);

        jLabel4.setText("Inleggeld:");

        jLabel5.setText("Maximaal aantal deelnemers:");

        jLabel6.setText("Aantal spelers per tafel:");

        jLabel2.setText("Naam:");

        MaxPlayersTourneyField.setEditable(false);

        jLabel7.setText("Locatie:");

        DateTourneyField.setEditable(false);

        NameTourneyField.setEditable(false);

        BacktoOverviewButton.setText("Terug naar overzicht");
        BacktoOverviewButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BacktoOverviewButtonActionPerformed(evt);
            }
        });

        PlayerList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane1.setViewportView(PlayerList);

        jLabel8.setText("Ingeschreven spelers:");

        EditPaymentStatusButton.setText("Betaalstatus wijzigen");
        EditPaymentStatusButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                EditPaymentStatusButtonActionPerformed(evt);
            }
        });

        lblCurrentLocation.setText("location");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(LocationEventMainButton, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(PlayerOverviewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(CurrentTourneyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 216, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(EditPaymentStatusButton)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel4)
                                    .addComponent(jLabel5)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel2))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(DateTourneyField)
                                    .addComponent(MaxPlayersTourneyField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(EntryFeeTourneyField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(TableCapTourneyField, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(NameTourneyField, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(77, 77, 77)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jLabel8)
                                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addComponent(EditTourneyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(BacktoOverviewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(lblCurrentLocation))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 111, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(CurrentTourneyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(PlayerOverviewButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(LocationEventMainButton, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lblCurrentLocation)
                        .addGap(35, 35, 35)
                        .addComponent(jLabel8))
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(NameTourneyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(DateTourneyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(MaxPlayersTourneyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(EntryFeeTourneyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel6)
                            .addComponent(TableCapTourneyField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(EditPaymentStatusButton)
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BacktoOverviewButton)
                    .addComponent(EditTourneyButton))
                .addContainerGap(47, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CurrentTourneyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CurrentTourneyButtonActionPerformed
        new CurrentTourneyOverview().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_CurrentTourneyButtonActionPerformed

    private void LocationEventMainButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LocationEventMainButtonActionPerformed
        new LocationEventOverview().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_LocationEventMainButtonActionPerformed

    private void PlayerOverviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PlayerOverviewButtonActionPerformed
        new PlayerOverview().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_PlayerOverviewButtonActionPerformed

    private void EditTourneyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditTourneyButtonActionPerformed
        new EditTourney().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_EditTourneyButtonActionPerformed

    private void BacktoOverviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BacktoOverviewButtonActionPerformed
        new TourneyOverview().setVisible(true);
        this.dispose();
    }//GEN-LAST:event_BacktoOverviewButtonActionPerformed

    private void EditPaymentStatusButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EditPaymentStatusButtonActionPerformed
        if (PlayerList.getSelectedValue() == null) {

            JOptionPane.showMessageDialog(null, "Geen Speler geselecteerd");
        } else {
            Player aPlayer = getPlayer();
            new EditPaymentStatus(aPlayer, anEvent).setVisible(true);
            this.dispose();
        }
    }//GEN-LAST:event_EditPaymentStatusButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DetailTourney.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DetailTourney.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DetailTourney.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DetailTourney.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new DetailTourney().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BacktoOverviewButton;
    private javax.swing.JButton CurrentTourneyButton;
    private javax.swing.JTextField DateTourneyField;
    private javax.swing.JButton EditPaymentStatusButton;
    private javax.swing.JButton EditTourneyButton;
    private javax.swing.JTextField EntryFeeTourneyField;
    private javax.swing.JButton LocationEventMainButton;
    private javax.swing.JTextField MaxPlayersTourneyField;
    private javax.swing.JTextField NameTourneyField;
    private javax.swing.JList PlayerList;
    private javax.swing.JButton PlayerOverviewButton;
    private javax.swing.JTextField TableCapTourneyField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblCurrentLocation;
    // End of variables declaration//GEN-END:variables
}
